package com.example.umikadmin;

import java.util.List;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;


import com.example.database.DataAccess;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.maps.model.PolylineOptions;




public class MapView extends FragmentActivity {	 
	  private GoogleMap map;
	  DataAccess data;
	  @Override
	  protected void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.map_view);
	    
	    int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());
	    
	    if(status!=ConnectionResult.SUCCESS){ 
	    	 
            int requestCode = 10;
            Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
            dialog.show();
         }
	     else 
	     {
 
            SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
            map = fm.getMap();
	    
        }
	    
	    drawMap();
	    
	   
	  }
	  
	  protected boolean isRouteDisplayed() {
	      return false;
	  }
	  private void drawMap()
	  {
		   LatLng p1 = new LatLng(52.219248,21.013217);
		   LatLng p2 = new LatLng(52.219909,21.012267);
		   LatLng p3 = new LatLng(52.219896,21.012031);
		   LatLng p4 = new LatLng(52.219949,21.01187);
		   LatLng p5 = new LatLng(52.219962,21.010744);
		   LatLng p6 = new LatLng(52.219327,21.010738);
		   LatLng p7 = new LatLng(52.218585,21.010674);
		   LatLng p8 = new LatLng(52.218503,21.012884); 
		   LatLng p9 = new LatLng(52.219042,21.012997); 
		   
		   
		   LatLng p10 = new LatLng(52.219967,21.010301);
		   LatLng p11 = new LatLng(52.219967,21.010301);
		   LatLng p12 = new LatLng(52.218646,21.01014);
		   
		   LatLng park = new LatLng(52.219612,21.011529);
		   LatLng budynek = new LatLng(52.21884,21.011755);
		   LatLng parking = new LatLng(52.219149,21.010585);
		   
		   
		   map.addPolyline(new PolylineOptions()
  	        .add(p1,p2,p3,p4,p5,p6,p1)
            .width(2)
 	        .color(Color.BLUE)
 	        );
		   map.addPolyline(new PolylineOptions()
 	        .add(p5,p10,p11,p12,p7)
           .width(2)
	        .color(Color.BLUE)
	        );
		   
		   map.addPolyline(new PolylineOptions()
	        .add(p6,p7,p8,p9,p1)
	        .width(2)
	        .color(Color.BLUE)
	        );
		   	drawGuards();
		   
		   map.moveCamera(CameraUpdateFactory.newLatLngZoom(budynek, 17));
		 //  map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
	  }
	  
	private  void drawGuards()
	  {
		
		String[] latlng = data.getGuardLocalization();
		
		String Lat_string=latlng[1];
		String Lng_string=latlng[2];
		
		double Lat=Double.parseDouble(Lat_string);
		double Lng=Double.parseDouble(Lng_string);
		
		
		LatLng guardposs = new LatLng(Lat,Lng);
		
		 Marker m1 = map.addMarker(new MarkerOptions()
	        .position(guardposs)
	        .title("Ochrona")
	        .snippet("Kami")
	        );
		
	  }
	  
}
